window.onload = () => {
  ; (() => {
    const userInfo = cache.getItem('userInfo')
    if (!userInfo?.id) return Message("请先登录")

    const incomeList = cache.getItem('incomeList') || []
    const incomeInfo = incomeList?.find(item => String(item.userId) === String(userInfo.id))
    const incomeIndex = incomeList?.findIndex(item => String(item.userId) === String(userInfo.id))

    const { proList = [] } = incomeInfo

    // 渲染列表
    const renderList = (lists) => {
      const domEl = document.querySelector('#personal .content2')
      domEl.innerHTML = ''

      const vDom = document.createDocumentFragment()
      lists.forEach(item => {
        const liEl = document.createElement('ul')
        liEl.innerHTML = `
      <li class="shoping">
        ${item.name}
      </li>
      <li class="shoping1">¥${item.price}</li>
      <li class="shoping2">¥${item.income}</li>
      <li class="shoping3">
        <a class='del' href='javascript:void(0);'>删除</a>
      </li>
      <li></li>
      `

        const del = liEl.querySelector('.del')

        del.addEventListener('click', () => {
          const isTrue = confirm('确认删除吗？')

          if (isTrue) {
            // 删除商品
            incomeInfo.proList = incomeInfo.proList?.filter(pro => pro.id !== item.id)

            incomeIndex[incomeIndex] = incomeInfo

            cache.setItem('incomeList', incomeList)
            renderList(incomeInfo.proList)

          }
        }, false)

        vDom.append(liEl)
      })
      domEl.append(vDom)
    }

    renderList(proList)



  })();
}